/**
 * @作者 伟子涵
 * @微信公号 搬砖暗夜码农
 * @开源项目 $ https://gitee.com/zhouwei5208888
 * @我的博客 $ http://itzhouwei.com
 * @创建时间 2023/7/14 10:09
 */
package com.itzhouwei.netty.day3;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.Charset;


/**
 * @description: 解码器
 * @author：zw，微信：yingshengzw
 * @date: 2023/7/14
 * @Copyright： 公众号：搬砖暗夜码农 | 博客：https://itzhouwei.com - 沉淀、分享、成长，让自己和他人都能有所收获！
 */
@SuppressWarnings("all")
@Slf4j
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel)  {
       //解码器
       //基于换行符号
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new LineBasedFrameDecoder(1024));
        //基于指定字符串换行符 这样功能等同于 LineBasedFrameDecoder    e.pipeline().addLast(new DelimiterBasedFrameDecoder(1024, false, Delimiters.lineDelimiter()));

        // 基于最大长度 e.pipeline().addLast(new FixedLengthFrameDecoder(4));

        // 解码转String，注意调整自己的编码格式GBK、UTF-8
        pipeline.addLast(new StringDecoder(Charset.forName("UTF-8")));

        pipeline.addLast(new MyZwServerHandler());
    }
}
